import React from 'react';
import ModalComp from '/common/components/ModalItem/ModalComp';
import { getConfigByKeyValue, isAuthByActionType } from '@/appConfig';
import { connect } from 'dva';

@connect(({ global: { appCode, userInfo } }) => ({ appCode, userInfo }))
class ModalItem extends React.Component {
  render() {
    const moreProps = {};
    // 如果没有保存权限，则隐藏 【确认】 按钮
    const userInfo = this.props.userInfo || {};
    const appConfigObj = getConfigByKeyValue('appCode', this.props.appCode);
    let hadAuth = isAuthByActionType(this.props.actionType, appConfigObj, userInfo.resources);

    if (!hadAuth) {
      moreProps.okButtonProps = { ...(this.props.okButtonProps || {}), disabled: true, style: { display: 'none' } };
      moreProps.cancelText = '返回';
    }

    return (
      <ModalComp
        {...this.props}
        {...moreProps}
      />
    );
  }
}

ModalItem.defaultProps = {
  ...ModalComp,
  actionType: 'save',
};

export default ModalItem;
